<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      fetch('http://localhost:1234/user', {
        method: 'POST',
        headers: {
          //消息头content-type描述要和body数据类型一致
          'content-type': 'application/json'
        },

        body: JSON.stringify({
          name: 'wang',
          age: 33
        })
      })
      .then(res => {
        if (res.ok) {
          return res.text()
        }
        throw new Error(`${res.status} ${res.statusText}`)
      })
      .then(data => {
        console.log(data)
      })
      .catch(err => {
        console.log(err.message)
      })

    </script>
  </body>
</html>
